package com.ruoyi.web.controller.config;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.vo.DeleteVo;
import com.ruoyi.system.entity.CataloguePortTree;
import com.ruoyi.system.service.CataloguePortTreeService;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 港口_文件管理目录树(CataloguePortTree)表控制层
 */
@RestController
@RequestMapping("cataloguePortTree")
public class CataloguePortTreeController extends BaseController {

    @Resource
    private CataloguePortTreeService cataloguePortTreeService;

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @GetMapping("/list")
    public TableDataInfo queryByPage(CataloguePortTree cataloguePortTree) {
        startPage();
        List<CataloguePortTree> list = cataloguePortTreeService.queryByPage(cataloguePortTree);
        return getDataTable(list);
    }


    /**
     * 树
     *
     * @return
     */
    @GetMapping("/tree")
    public ResponseEntity<List<CataloguePortTree>> tree() {
        List<CataloguePortTree> list = cataloguePortTreeService.tree();
        return ResponseEntity.ok(list);
    }


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<CataloguePortTree> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.cataloguePortTreeService.queryById(id));
    }


    /**
     * 新增数据
     *
     * @param cataloguePortTree 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    public ResponseEntity<CataloguePortTree> add(@RequestBody CataloguePortTree cataloguePortTree) {
        return ResponseEntity.ok(this.cataloguePortTreeService.insert(cataloguePortTree));
    }


    /**
     * 编辑数据
     *
     * @param cataloguePortTree 实体
     * @return 编辑结果
     */
    @PostMapping("/edit")
    public ResponseEntity<CataloguePortTree> edit(@RequestBody CataloguePortTree cataloguePortTree) {
        return ResponseEntity.ok(this.cataloguePortTreeService.update(cataloguePortTree));
    }

    /**
     * 删除数据
     *
     * @param deleteVo 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/delete")
    public ResponseEntity<Boolean> deleteById(@Validated @RequestBody DeleteVo deleteVo) {
        return ResponseEntity.ok(this.cataloguePortTreeService.deleteById(deleteVo.getId()));
    }

}

